package com.qxbb.report.controller;

import com.qxbb.report.bo.ImgBo;
import com.qxbb.report.bo.ProductHistoryBO;
import com.qxbb.report.service.IChainInOutStockService;
import com.qxbb.report.service.ProductService;
import com.qxbb.report.utils.http.HttpResult;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @Author: pebble
 * @CreateTime: 2023-11-22  14:31
 * @Description: 公用controlloer
 * @Version: 1.0
 */
@RequestMapping
@RestController
@CrossOrigin
public class CommonController {

    Logger logger = LoggerFactory.getLogger(LoginController.class);

    @Autowired
    private ProductService productService;
    @Autowired
    private IChainInOutStockService chainInOutStockService;

    /**
     * 暂时不用
     *
     * 根据条形码验证压缩图片是否存在
     *
     * @param barcode
     * @return
     * @throws IOException
     */
    @GetMapping("/getImg/{barcode}")
    public HttpResult getImg(@PathVariable("barcode") String barcode) throws IOException {
        logger.info(this.getClass() + "getImg 根据条形码验证压缩图片是否存在:{}", barcode);
        return HttpResult.ok(productService.getImgNetworkURL(barcode));

    }


    /**
     * 根据货号和条形码查询图片信息
     * @param
     * @return
     * @throws IOException
     */
    @PostMapping("/Img/info")
    public HttpResult selectImgByLike(@RequestBody ImgBo imgBo) throws IOException {
        logger.info(this.getClass() + "selectImgByLike 根据货号和条形码查询图片信息:{}", imgBo);
        return HttpResult.ok(productService.selectImgByLike(imgBo));

    }


    /**
     * 根据店铺ID和条码查询跟踪产品库存信息
     * @param
     * @return
     * @throws IOException
     */
    @PostMapping("/productHistory")
    public HttpResult selectProductHistory(@RequestBody ProductHistoryBO productHistoryBO)  {
        logger.info(this.getClass() + "selectProductHistory 根据店铺ID和条码查询跟踪产品库存信息:{}", productHistoryBO);
        return HttpResult.ok(chainInOutStockService.selectProductHistory(productHistoryBO));

    }


    /**
     * 根据货号模糊查询产品信息
     * @param
     * @return
     * @throws IOException
     */
    @PostMapping("/likeProduct/{productCode}/{chainUserId}")
    public HttpResult selectLikeProduct(@PathVariable("productCode") String productCode,@PathVariable("chainUserId")Integer chainUserId)  {
        logger.info(this.getClass() + "selectLikeProduct 根据货号模糊查询产品信息:{}", productCode,chainUserId);
        return HttpResult.ok(productService.selectLikeProduct(productCode,chainUserId));

    }



}
